import 'package:erp/UI/Pages/ActionItemMetaData.dart';
import 'package:erp/UI/Pages/SalesPages/SalesOrderPage.dart';
import 'package:erp/UI/Pages/SettingsPages/SettingsPage.dart';
import 'package:erp/UI/Pages/WareHouseManagement/WareHouseManagementPage.dart';
import 'package:erp/UI/Routes.dart';
import 'package:flutter/material.dart';
import '../CodeResources/Colors.dart';
//import 'package:fcharts/fcharts.dart';

class HomePage extends StatelessWidget {

//  static const myData = [
//    ["A", "✔"],
//    ["B", "❓"],
//    ["C", "✖"],
//    ["D", "❓"],
//    ["E", "✖"],
//    ["F", "✖"],
//    ["G", "✔"],
//  ];


  @override
  Widget build(BuildContext context) {
    var actions = getActions(context);
    return CustomScrollView(
      slivers: <Widget>[
        SliverAppBar(
//          backgroundColor: Colors.white,
          expandedHeight: 200.0,
          actions: <Widget>[
            IconButton(icon: Icon(Icons.search), onPressed: (){

            }),
            Expanded(
                child: Center(
                  child: TextField(
                    textAlign: TextAlign.center,
                    decoration: InputDecoration(
                        filled: true,
                        contentPadding: EdgeInsets.all(6.0),
                        fillColor: Colors.white30,
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(8.0)),
                            borderSide: BorderSide(color: Colors.transparent)
                        ),
                        border: OutlineInputBorder(
                            borderRadius: BorderRadius.all(Radius.circular(8.0)),
                            borderSide: BorderSide(color: Colors.transparent)
                        ),
                        focusedBorder: OutlineInputBorder(
                            borderRadius: BorderRadius.all(Radius.circular(8.0)),
                            borderSide: BorderSide(color: Colors.transparent)
                        )
                    ),
                  ),
                )
            ),
            IconButton(icon: Icon(Icons.apps), onPressed: (){

            }),
          ],
          flexibleSpace: FlexibleSpaceBar(
//            background: Container(
//              margin: EdgeInsets.only(top: 30.0),
//              child: LineChart(
//                lines: [
//                  new Line<List<String>, String, String>(
//                    data: myData,
//                    xFn: (datum) => datum[0],
//                    yFn: (datum) => datum[1],
//                    stroke: PaintOptions.stroke(color: Colors.white70, strokeCap: StrokeCap.round),
//                    marker: MarkerOptions(paint: PaintOptions.fill(color: Colors.white70))
//                  ),
//                ],
//              ),
//            )
          ),
        ),
        SliverGrid(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
//              crossAxisSpacing: 5.0,
//              mainAxisSpacing: 5.0,
          ),
          delegate: SliverChildListDelegate(actions)
        )
      ],
    );
  }

  var _imageSize = 50.0;
  var _color = themeColor;
  List<Widget> getActions(BuildContext context) => [
    buildAction(ActionItemMeta(label: "مال ئەكىرىش", heroName: "PurchaseHero", assetsImageName: "assets/pictures/import.png", action: (){
      Navigator.of(context).pushNamed(PagesRouter.purchaseOrderPage);
    }), ),
    buildAction(ActionItemMeta(label: "سىتىش", heroName: "SalesHero", assetsImageName: "assets/pictures/cells.png", action: (){
      Navigator.of(context).push(MaterialPageRoute(builder: (context) => SalesOrderPage()));
    }), ),
    buildAction(ActionItemMeta(label: "ئامبار باشقۇرۇش", heroName: "WareHouseHero", assetsImageName: "assets/pictures/warehause.png", action: (){
      Navigator.of(context).push(MaterialPageRoute(builder: (context) => WareHouseManagementPage()));
    }), ),
    buildAction(ActionItemMeta(label: "ئاساسى ئۇچۇرلار", heroName: "BasicInformationManagement", assetsImageName: "assets/pictures/team.png", action: (){
      Navigator.of(context).pushNamed(PagesRouter.basicInformationManagementPage);
    }), ),
    buildAction(ActionItemMeta(label: "مالىيە ئۇچۇرى", heroName: "FinanceHero", assetsImageName: "assets/pictures/finance.png", action: (){

    }), ),
    buildAction(ActionItemMeta(label: "تەڭشەكلەر", heroName: "SettingsHero", assetsImageName: "assets/pictures/settings.png", action: (){
      Navigator.of(context).push(MaterialPageRoute(builder: (context) => SettingsPage()));
    }), ),
  ];

  Widget buildAction(ActionItemMeta action){
    return GestureDetector(
      child: Column (
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Hero(
            tag: action.heroName, child: Image.asset(action.assetsImageName, width: _imageSize, height: _imageSize,),
          ),
          Text(action.label)
        ],
      ),
      onTap: action.action,
    );
  }
}

